package cn.jekun.shop.app.action;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import net.sf.json.JSONObject;
import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.component.base.utils.SqlUtis;
import cn.jekun.component.core.Constants;
import cn.jekun.component.core.bean.gen.ErpSalePrice;
import cn.jekun.component.core.bean.gen.McMember;
import cn.jekun.component.core.service.gen.ErpSalePriceService;
import cn.jekun.component.core.service.gen.McMemberService;
import cn.jekun.shop.common.service.ShopService;
/**
 * 鍟嗗淇℃伅
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class ShopAction1 extends AppBaseAction{
	private static Logger logger=Logger.getLogger(ShopAction.class);
	@Resource(name = ShopService.BEAN_NAME)
	protected ShopService shopService;
	@Resource(name = McMemberService.BEAN_NAME)
	McMemberService memberService;
	private String shopName ;
	private String tempShopId;
	private String userId;
	
	@Resource(name = ErpSalePriceService.BEAN_NAME)
	private ErpSalePriceService erpSalePriceService;
	
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getShopName() {
		return shopName;
	}
	public void setShopName(String shopName) {
		this.shopName = shopName;
	}
	public String getTempShopId() {
		return tempShopId;
	}
	public void setTempShopId(String tempShopId) {
		this.tempShopId = tempShopId;
	}
	/**
	 * 棣栭〉鎺ㄨ崘鍟嗗鍒楄〃
	 * @return
	 */
	public String recommendShopList(){
		JSONObject jsonObject = null;
		try{
			String lng = this.request.getParameter("lng");//缁忓害
			String lat = this.request.getParameter("lat");//绾害
			String currentCityId = this.request.getParameter("currentCityId");//褰撳墠鍩庡競缂栫爜(闄勮繎)
			this.validateSign(lng,lat,currentCityId);
			jsonObject = shopService.recommendShopList(lng,lat,currentCityId);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	
	
	/**
	 * 鍟嗗鍒楄〃
	 * @return
	 */
	public String shopList(){
		JSONObject jsonObject = null;
		try{
		String pageSize = this.request.getParameter("pageSize");//椤靛ぇ灏�
		String currentPage = this.request.getParameter("currentPage");//褰撳墠椤�
		String typeId = this.request.getParameter("typeId");//鍟嗗绫诲瀷缂栫爜
		String lng = this.request.getParameter("lng");//缁忓害
		String lat = this.request.getParameter("lat");//绾害
		String cityId = this.request.getParameter("cityId");//宸插紑閫氬煄甯傜紪鐮�(棣栭〉)
		String shopName = this.request.getParameter("shopName");//鍟嗗鍚嶇О
		String speTypeId = this.request.getParameter("speTypeId");//鐗硅壊
		String sort = this.request.getParameter("sort");//鎺掑簭瀛楁   0锛氭渶杩�   1锛氳捣閫侀噾棰濇渶灏�    2锛氶粯璁ゆ帓搴�
		String shopId = this.request.getParameter("shopId");//鍟嗗缂栫爜
		String distance = this.request.getParameter("distance");//璺濈
		String currentCityId = this.request.getParameter("currentCityId");//褰撳墠鍩庡競缂栫爜(闄勮繎)
		this.validateSign(pageSize,currentPage,typeId,lng,lat,cityId,shopName,speTypeId,sort,shopId);
		jsonObject = shopService.queryList(pageSize,currentPage,typeId,lng,lat,cityId,shopName,speTypeId,sort,shopId,distance,currentCityId);
		System.out.println("jsonObject ====================================== " + jsonObject);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
		
	}
	/**
	 * 鍟嗗鍟嗗搧鍒嗙被(app鍟嗗鍟嗗搧鍒嗙被锛屾垨鍟嗗搧绠＄悊鐨勫晢鍝佸垎绫伙紝閫氳繃customFlag鍖哄垎)
	 * @return
	 */
	public String shopGoodsType(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");//鍟嗗缂栫爜
			String parentId = this.request.getParameter("parentId");//鍟嗗鍟嗗搧绫诲瀷琛ㄤ腑鐨勭埗鍒嗙被浠ｇ爜
			String customFlag = this.request.getParameter("customFlag");//鍟嗗搧绠＄悊-鍟嗗搧鍒嗙被浣跨敤銆備笉杩囨护娌℃湁鍟嗗搧鐨勫垎绫�
			this.validateSign(shopId,parentId);
			
			//BOX-825
//			String model = this.request.getParameter("model");
//			if (StringUtils.isNotBlank(model)) {//TODO 鍒犻櫎杩欎釜鍒ゆ柇
//				jsonObject = shopService.shopGoodsType(parentId, shopId);
//			}else{
				if (StringUtils.isNotBlank(customFlag)) {//鍟嗗搧绠＄悊-鏈簵鍟嗗搧鍒嗙被
					jsonObject = shopService.getShopGoodsType(parentId, shopId);
				}else{//鍟嗗搧鍒楄〃-鍟嗗搧鍒嗙被
					jsonObject = shopService.shopGoodsType(parentId, shopId);
				}
//			}
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 鍏虫敞鍟嗗
	 * @return
	 */
	public String concernShop(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			this.validateLoginApp();
			this.validateSign(getLoginSign(),getUserId(),shopId);
			jsonObject = shopService.concernShop(getUserId(),shopId);
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "鍏虫敞鍟嗗鎴愬姛"+shopId+"锛屾潵婧�:mobile");//璁板綍鎿嶄綔鏃ュ織

		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "鍏虫敞鍟嗗澶辫触锛屽師鍥�:"+jsonObject.get("message")+",鏉ユ簮:mobile");//璁板綍鎿嶄綔鏃ュ織

		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 鍙栨秷鍏虫敞鍟嗗
	 * @return
	 */
	public String cancleConcernShop(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			this.validateLoginApp();
			this.validateSign(getLoginSign(),getUserId(),shopId);
			jsonObject = shopService.cancleConcernShop(getUserId(),shopId);
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "鍙栨秷鍏虫敞鍟嗗"+shopId+"鎴愬姛");//璁板綍鎿嶄綔鏃ュ織

		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
			this.logService.addMallLog(this.getUserId(), 
					this.getBrowser(), this.getIp(), "鍙栨秷鍏虫敞鍟嗗澶辫触锛屽師鍥�:"+jsonObject.get("message")+",鎿嶄綔鏉ユ簮:"+this.getUserId());//璁板綍鎿嶄綔鏃ュ織

		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	/*
	 * 閫氳繃shopId鑾峰彇鍟嗗淇℃伅
	 */
	public String getShopInfo(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			jsonObject = this.shopService.getShopIndo(shopId);
			
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		if(jsonObject.get("code").equals("1")){
			shopName = jsonObject.getString("shopName").toString();
			tempShopId = jsonObject.getString("shopId").toString();
			userId = "";
			
		}else{
			shopName = "浜戜究鍒╁晢搴�";
			tempShopId = "";
			userId = "";
		}
		return "/reg/reg.jsp";
	}
	/*
	 * 閫氳繃shopId鑾峰彇鍟嗗淇℃伅 _wifi鏀寔
	 */
	public String getWifiShopInfo(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			jsonObject = this.shopService.getShopIndo(shopId);
			
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		if(jsonObject.get("code").equals("1")){
			shopName = jsonObject.getString("shopName").toString();
			tempShopId = jsonObject.getString("shopId").toString();
			
		}else{
			shopName = "浜戜究鍒╁晢搴�";
			tempShopId = "";
		}
		return "/wifi/reg.jsp";
	}
	
	/**
	 * 
	* @Title: switchShopBusinessStatus
	* @Description: 鍒囨崲鍟嗗鐨勭姸鎬�
	* @param @return    璁惧畾鏂囦欢
	* @return String    杩斿洖绫诲瀷
	* @throws
	 */
	public String switchShopBusinessStatus(){
		JSONObject jsonObject = null;
		try{
			logger.info("========================ShopAction switchShopBusinessStatus============================");
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			String businessStatus = this.request.getParameter("businessStatus");
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),shopId,userId,businessStatus);
			logger.info("=========================鍙傛暟shopId = "+shopId+":businessStatus="+businessStatus+"==========================================================");
		    jsonObject = this.shopService.switchBusinessStatus(shopId, businessStatus);
		    
		    this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "鎵嬫満鍟嗗"+shopId+"鍒囨崲钀ヤ笟妯″紡"+businessStatus);//璁板綍鎿嶄綔鏃ュ織
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/***
	 * 
	* @Title: showShopIntroduction
	* @Description:   鍟嗗绠�浠�
	* @param @return    璁惧畾鏂囦欢
	* @return String    杩斿洖绫诲瀷
	* @throws
	 */
	public String showShopIntroduction(){
		JSONObject  jsonObject = null;
		try{
			logger.info("==================================ShopAction showShopIntroduction=============================================");
			String shopId = this.request.getParameter("shopId");
			this.validateSign(shopId);
            logger.info("===================================璇锋眰鍙傛暟锛歴hopId = "+shopId+"=============================================================");
			jsonObject = this.shopService.getShopIntroduct(shopId);
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 *  淇敼骞朵繚瀛樺晢瀹剁殑绠�浠�
	 *  @return
	 *
	 */
	public String modifyShopIntroduction(){
		JSONObject  jsonObject = null;
		try{
			logger.info("==================================ShopAction modifShopIntroduction begin=============================================");
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			String introduction = this.request.getParameter("introduction");
			
			String sourceTxt = "shopId="+shopId+":introduction="+introduction;
			logger.info("===================================璇风粓绔痑pp涓婁紶鐨勫弬鏁帮細 "+sourceTxt+"=============================================================");
		    //鐧诲綍绛惧悕楠岃瘉			
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId);
            
			jsonObject = this.shopService.modifyShopIntroduction(shopId,introduction);
			
			logger.info("==================================ShopAction modifShopIntroduction end=============================================");
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "鎵嬫満鍟嗗"+shopId+"淇敼绠�浠�");//璁板綍鎿嶄綔鏃ュ織
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
    /**
     * 
    * @Title: shopShowBusinessStatus
    * @Description: 鍒濆鍖栧晢瀹剁殑钀ヤ笟鐘舵��
    * @param @return    璁惧畾鏂囦欢
    * @return String    杩斿洖绫诲瀷
    * @throws
     */
	public String shopShowBusinessStatus(){
		JSONObject jsonObject = null;
		try{
			logger.info("=============================ShopAction shopShowBusinessStatus====================================");
			String shopId = this.request.getParameter("shopId"); 
			this.validateSign(shopId);
			logger.info("=============================鍙傛暟锛�"+shopId+"====================================");
			jsonObject = this.shopService.getShopIndoBusinesStatus(shopId);
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 鑾峰彇鍟嗗鐨勫熀鏈俊鎭�
	 *  @return
	 *
	 */
	public String getShopInfoByShopId(){
		JSONObject jsonObject = null;
		try{
			logger.info("=====================================ShopAction getShopInfoByShopId begin==============================================");
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");

			String sourceTxt = "shopId="+shopId+":userId="+userId;
			logger.info("=========================================缁堢涓婇�佺殑鍙傛暟锛�"+sourceTxt+"======================================================");
//			鐧诲綍鍜岀鍚嶉獙璇�
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId);
			
			jsonObject = this.shopService.getShopInfoByShopId(shopId);
			
            logger.info("=======================jsonObject="+jsonObject);
			logger.info("==========================================ShopAction getShopInfoByShopId end=========================================");
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 鑾峰彇鍟嗗绫诲瀷鍒楄〃
	 *  @return
	 *
	 */
	public String getShopType(){
		JSONObject jsonObject = null;
		try{
			logger.info("=====================================ShopAction getShopType begin==============================================");
			String userId = this.request.getParameter("userId");
			//绛惧悕楠岃瘉
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId);
			
			jsonObject = this.shopService.getShopType();
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 淇敼鍟嗗鐨勫熀鏈俊鎭�
	 *  @return
	 *
	 */
	public String updateShopMessage(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction updateShopMessage begin==========================");
			   String logoUrl = this.request.getParameter("logoUrl"); //logo鍥剧墖
		       String shopName = this.request.getParameter("shopName"); //绠�绉�
		       String comName = this.request.getParameter("comName"); //鍏ㄧО
		       String shopTypeId = this.request.getParameter("shopTypeId"); //鍟嗗绫诲瀷
		       String phone = this.request.getParameter("phone"); //鍥哄畾鐢佃瘽
	           String mobile = this.request.getParameter("mobile"); //鎵嬫満鍙风爜
	           String contact = this.request.getParameter("contact"); //鑱旂郴浜�
	           String businessHours = this.request.getParameter("businessHours"); //钀ヤ笟鏃堕棿
	           String minAmount = this.request.getParameter("minAmount"); //璧烽�侀噾棰�
	           String range = this.request.getParameter("range"); //閰嶉�佽寖鍥�
	           String address = this.request.getParameter("address");//鍦板潃
	           String street = this.request.getParameter("street"); //璇︾粏鍦板潃
	           String shopId = this.request.getParameter("shopId");
	           String userId = this.request.getParameter("userId");
	           String provinceId = this.request.getParameter("provinceId");//鐪佷唤浠ｇ爜
	           String cityId = this.request.getParameter("cityId"); //鍩庡競浠ｇ爜
	           String regionId = this.request.getParameter("regionId"); //鍖哄煙浠ｇ爜
	           String longItude = this.request.getParameter("longItude"); //缁忓害
	           String latItude = this.request.getParameter("latItude"); //绾害
	           String isZiti = this.request.getParameter("isZiti");//鏄惁鑷彁
	           String deliveryAmount = this.request.getParameter("deliveryAmount");//閰嶉�佽垂
	           
	           String sourceTxt = "logoUrl="+logoUrl+":shopName="+shopName+":comName="+comName+":shopTypeId="+shopTypeId+":phone="+phone+":mobile="+mobile+
	        		               ":contact="+contact+":businessHourse="+businessHours+":minAmount="+minAmount+":range="+range+":address="+address+":street="
	        		                +street+":shopId="+shopId+"userId="+userId+"provinceId="+provinceId+"cityId="+cityId+":regionId="+regionId+"longItude="+logoUrl
	        		                +"latiItude="+latItude+"isZiti"+isZiti+"deliveryAmount="+deliveryAmount;
	           logger.info("===================================缁堢app涓婁紶鐨勫弬鏁颁负锛�"+sourceTxt+"==========================================");
	           //鐧诲綍楠岃瘉鍜岀鍚�
	           this.validateLoginApp();
	           this.validateSign(this.getLoginSign(),userId,shopId,logoUrl,shopName,comName,shopTypeId,phone,mobile,contact,businessHours,
	        		   minAmount,range,address,street,provinceId,cityId,regionId,longItude,latItude,isZiti,deliveryAmount);
	           
	           jsonObject = this.shopService.updateShopMessage(shopId, logoUrl, shopName, comName, shopTypeId, phone, mobile, contact, businessHours, minAmount, range, address, street, provinceId, cityId, regionId, longItude, latItude,isZiti,deliveryAmount);
	           logger.info("==================================ShopAction updateShopMessage begin===========================================");
	           this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "鎵嬫満鍟嗗"+shopId+"淇敼鍩烘湰淇℃伅");//璁板綍鎿嶄綔鏃ュ織
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 *  鑾峰彇鍟嗗鐨勭浉鍐�
	 *  @return
	 *
	 */
	public String getShopPic(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction getShopPic begin==========================");
			String userId = this.request.getParameter("userId");
			String shopId = this.request.getParameter("shopId");
			
			String sourceTxt = "userId ="+userId+":shopId="+shopId;
			logger.info("==========================缁堢app涓婁紶鐨勫弬鏁帮細"+sourceTxt+"======================================");
            //鐧诲綍绛惧悕楠岃瘉			
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId);
			
			jsonObject = this.shopService.getShopPics(shopId);
			logger.info("============================ShopAction getShopPic end==========================");
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 娣诲姞鍟嗗鍥剧墖淇℃伅
	 *  @return
	 *
	 */
	public String addShopPic(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction modifyOrDelShopPic begin==========================");
			String userId = this.request.getParameter("userId");
			String shopId = this.request.getParameter("shopId");
			String shopPicUrl = this.request.getParameter("shopPicUrl");
			
			String sourceTxt = "userId ="+userId+":shopId="+shopId+":shopPicUrl="+shopPicUrl;
			logger.info("==========================缁堢app涓婁紶鐨勫弬鏁帮細"+sourceTxt+"======================================");
//			鐧诲綍楠岃瘉绛惧悕
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId,shopPicUrl);
			
			jsonObject = this.shopService.addShopPic(shopId,userId,shopPicUrl);
			
			logger.info("============================ShopAction getShopPic end==========================");
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "鎵嬫満鍟嗗"+shopId+"澧炲姞鍟嗗鐩稿唽鍥剧墖");//璁板綍鎿嶄綔鏃ュ織
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 *  鍒犻櫎鍟嗗鍥剧墖
	 *  @return
	 *
	 */
	public String delShopPic(){
		JSONObject jsonObject = null;
		try{
			logger.info("============================ShopAction delShopPic begin==========================");
			String userId = this.request.getParameter("userId");
			String shopId = this.request.getParameter("shopId");
			String shopPicId = this.request.getParameter("shopPicId");
			
			String sourceTxt = "userId ="+userId+":shopId="+shopId+":shopPicId="+shopPicId;
			logger.info("==========================缁堢app涓婁紶鐨勫弬鏁帮細"+sourceTxt+"======================================");
			
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,shopId,shopPicId);
			
			jsonObject = this.shopService.delShopPic(shopPicId);
			
			logger.info("============================ShopAction delShopPic end==========================");
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "鎵嬫満鍟嗗"+shopId+"鍒犻櫎鍟嗗鐩稿唽鍥剧墖");//璁板綍鎿嶄綔鏃ュ織
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 鏌ヨ鍟嗗鍏憡鍜岀粡钀ョ姸鎬�
	 * @return
	 */
	public String showShopNoticeAndBusinessStatus(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			this.validateSign(shopId);
			jsonObject = this.shopService.showShopNoticeAndBusinessStatus(shopId);
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 搴楅摵璇︽儏
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String queryShopMessage(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			this.validateSign(shopId);
			jsonObject = this.shopService.queryShopMessage(shopId,userId);
			if(StringUtils.isNotBlank(userId) && jsonObject.get("shop") != null){
				formMap.put(McMember.COL_SHOP_ID, shopId);
				formMap.put(McMember.COL_USER_ID, userId);
				formMap.put(McMember.COL_CONCERN, "1");
				SqlUtis.prepareSql(formMap, 
						SqlUtis.getSQL(formMap, McMember.COL_SHOP_ID,Types.VARCHAR,SqlUtis.EQ),
						SqlUtis.getSQL(formMap, McMember.COL_CONCERN,Types.VARCHAR,SqlUtis.EQ)
						,SqlUtis.getSQL(formMap, McMember.COL_USER_ID,Types.VARCHAR,SqlUtis.EQ));
				JSONObject json = (JSONObject)jsonObject.get("shop");
				if(this.memberService.exists(formMap)){
					json.put("memberflag", "1");
				}else{
					json.put("memberflag", "0");
				}
			}
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	
	
	/**
	 * 寮�搴楄幏鍙栧晢瀹跺垎绫�
	 * @return
	 */
	public String getOpenShopType(){
		JSONObject jsonObject = null;
		try{
			String parentId=this.request.getParameter("parentId");
			jsonObject = this.shopService.getOpenShopType(parentId);
			//杩斿洖寮�搴楁敮浠樻湇鍔�
			
			//寮�搴楁湇鍔＄殑浠锋牸
			Map saleMap = new HashMap();
			saleMap.put(ErpSalePrice.COL_MERCHANDISE_ID, Constants.ERP_SHOP_FUWU.ONLIE_PAYMENT);
			SqlUtis.prepareSql(saleMap,SqlUtis.getSQL(saleMap, ErpSalePrice.COL_MERCHANDISE_ID,Types.VARCHAR,SqlUtis.EQ));
			ErpSalePrice erpSalePrice = erpSalePriceService.one(saleMap);
			if (erpSalePrice != null && erpSalePrice.getPrice()!=null ) {
				jsonObject.put("price", erpSalePrice.getPrice());
			}else {
				jsonObject.put("price", "0");
			}
			
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 寮�搴椾繚瀛樺晢瀹朵俊鎭�
	 * @return
	 */
	public String openShop(){
		JSONObject jsonObject = null;
		try{
			String shopName = request.getParameter("shopName");//鍟嗗簵鍚嶇О
			String identityNo = request.getParameter("identityNo");//韬唤璇佸彿鐮�
			String identityImage1 = request.getParameter("identityImage1");//韬唤璇佸浘鐗嘇
			String identityImage2 = request.getParameter("identityImage2");//韬唤璇佸浘鐗嘊
			String identityImage3 = request.getParameter("identityImage3");//韬唤璇佸浘鐗嘋
			String provinceId = request.getParameter("provinceId");//鐪佷唤浠ｇ爜
			String cityId = request.getParameter("cityId");//鍩庡競浠ｇ爜
			String regionId = request.getParameter("regionId");//鍖哄煙浠ｇ爜
			String address = request.getParameter("address");//璇︾粏鍦板潃
			String street = request.getParameter("street"); //琛楅亾
			String longitude = request.getParameter("longitude");//缁忓害
			String latitude = request.getParameter("latitude");//绾害
			String phone = request.getParameter("phone");//鑱旂郴鐢佃瘽
			String mobile = request.getParameter("mobile");//鑱旂郴鎵嬫満
			String psw = request.getParameter("psw");//鍟嗗鏀粯瀵嗙爜
			String shopTypeId = request.getParameter("shopTypeId");//鍟嗗鏀粯瀵嗙爜
			String email = request.getParameter("email");//寮�搴楅偖绠�
			String range = request.getParameter("range");//閰嶉�佽寖鍥�
			
			String certificate1 = request.getParameter("certificate1");//璇佷欢1
			String certificate2 = request.getParameter("certificate2");//璇佷欢2
			String certificate3 = request.getParameter("certificate3");//璇佷欢3
			String certificate4 = request.getParameter("certificate4");//璇佷欢4
			String certificate5 = request.getParameter("certificate5");//璇佷欢5
			
			
			this.validateLoginApp();
			this.validateSign(shopName,identityNo);
			
			jsonObject = this.shopService.openShop(shopName,identityNo,identityImage1,identityImage2,identityImage3,
					provinceId,cityId,regionId,address,street,longitude,latitude,phone,mobile,psw,
					certificate1,certificate2,certificate3,certificate4,certificate5,getUserId(),shopTypeId,email,range);
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "鎵嬫満鍟嗗寮�搴�");//璁板綍鎿嶄綔鏃ュ織
			
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 淇敼钀ヤ笟鐘舵�佺被鍨�
	 * @return
	 */
	public String updateBusinessStatusType(){
		JSONObject jsonObject = null;
		try{
			String shopId = this.request.getParameter("shopId");
			String userId = this.request.getParameter("userId");
			String businessStatusType = this.request.getParameter("businessStatusType");
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),shopId,userId,businessStatusType);
			 jsonObject = this.shopService.switchBusinessStatusType(shopId, businessStatusType);
			 
			 this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "鎵嬫満鍟嗗"+shopId+"淇敼钀ヤ笟鐘舵��"+businessStatusType);//璁板綍鎿嶄綔鏃ュ織
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
		
	}
  }
